#include "dbworker.h"

#include <iostream>
using namespace std;


DbWorker::DbWorker()
{
    sqlite3_open("../database.db", &conn);
}

vector<vector<string> > DbWorker::select(string query)
{
//sqlite3_stmt *statement;
vector<vector<string> > results;

            sqlite3_prepare_v2(this->conn, query.c_str(), -1, &this->stat, 0);

            int cols = sqlite3_column_count(this->stat);
            int result = 0;
            while(true)
            {
                    result = sqlite3_step(this->stat);

                    if(result == SQLITE_ROW)
                    {
                            vector<string> values;
                            for(int col = 0; col < cols; col++)
                            {
                                string s = "";
                                s = (char*)sqlite3_column_text(this->stat, col);
                                values.push_back(s);
                            }
                            results.push_back(values);
                    }
                    else
                    {
                            break;
                    }
            }

            sqlite3_finalize(this->stat);
    return results;
}
